VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsConfig"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
'==================================================================================
'Copyright (c) 2003, Andrew Jeremy Gargan (ajg@osite.co.za), Terence Leslie Van Zyl (tvz@osite.co.za)
'
'All rights reserved.
'
'Redistribution and use in source and binary forms, with or without modification,
'are permitted provided that the following conditions are met:
'
'Redistributions of source code must retain the above copyright notice, this list
'of conditions and the following disclaimer.
'
'Redistributions in binary form must reproduce the above copyright notice, this
'list of conditions and the following disclaimer in the documentation and/or other
'materials provided with the distribution.
'
'Neither the name of the <ORGANIZATION> nor the names of its contributors may be
'used to endorse or promote products derived from this software without specific
'prior written permission.
'
'THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
'ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
'WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
'IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
'INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
'BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
'DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
'LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
'OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
'OF THE POSSIBILITY OF SUCH DAMAGE.
'===================================================================================
Dim mvarImagePath As String
Dim mvarDataPath As String

Dim mvarEmailUser As String
Dim mvarEmailPassword As String
Dim mvarEmailAddress As String

Dim mvarConfigured As Boolean

Public Property Let DataPath(aPath As String)
    mvarDataPath = aPath
End Property

Public Property Get DataPath() As String
    DataPath = mvarDataPath
End Property

Public Property Let ImagePath(aPath As String)
    mvarImagePath = aPath
End Property

Public Property Get ImagePath() As String
    ImagePath = mvarImagePath
End Property

Public Property Get configured() As Boolean
    configured = mvarConfigured
End Property

Public Property Let EmailUser(aUser As String)
    mvarEmailUser = aUser
End Property

Public Property Get EmailUser() As String
    EmailUser = mvarEmailUser
End Property

Public Property Let EmailAddress(anAddress As String)
    mvarEmailAddress = anAddress
End Property

Public Property Get EmailAddress() As String
    EmailAddress = mvarEmailAddress
End Property

Public Property Let EmailPassword(aPassword As String)
    mvarEmailPassword = aPassword
End Property

Public Property Get EmailPassword() As String
    EmailPassword = mvarEmailPassword
End Property

Public Sub Get_Config()
    Dim lvarRS As DAO.Recordset
    Dim lvarQuery As String
    
    lvarQuery = "SELECT * FROM CONFIG WHERE CON_KEY=1"
    Set lvarRS = gvarDatabase.OpenRecordset(lvarQuery, dbOpenForwardOnly)
    
    If Not lvarRS.EOF Then
        mvarDataPath = lvarRS("CON_DATA_DIR")
        mvarImagePath = lvarRS("CON_IMAGE_DIR")
        mvarEmailUser = lvarRS("CON_EMAIL_USER")
        mvarEmailAddress = lvarRS("CON_EMAIL_ADDRESS")
        mvarEmailPassword = lvarRS("CON_EMAIL_PASSWORD")
    Else
        mvarDataPath = VB.App.Path & "\data"
        mvarImagePath = VB.App.Path & "\images"
        mvarEmailUser = " "
        mvarEmailAddress = " "
        mvarEmailPassword = " "
        
        Save_Config
    End If

    mvarConfigured = True
End Sub

Public Sub Save_Config()
    Dim lvarQuery As String
    
    'check for no config
    lvarQuery = "INSERT INTO CONFIG (CON_KEY,CON_DATA_DIR,CON_IMAGE_DIR,CON_EMAIL_ADDRESS,CON_EMAIL_USER,CON_EMAIL_PASSWORD) " & _
                "VALUES (1,'" & mvarDataPath & "','" & mvarImagePath & "','" & mvarEmailUser & "','" & mvarEmailAddress & "','" & mvarEmailPassword & "');"
    On Error Resume Next
    gvarDatabase.Execute lvarQuery, dbFailOnError
    On Error GoTo 0
                    
    'if config update
    lvarQuery = "UPDATE CONFIG SET CON_DATA_DIR ='" & mvarDataPath & "'," & _
                " CON_IMAGE_DIR='" & mvarImagePath & "'," & _
                " CON_EMAIL_ADDRESS='" & mvarEmailAddress & "'," & _
                " CON_EMAIL_USER='" & mvarEmailUser & "'," & _
                " CON_EMAIL_PASSWORD='" & mvarEmailPassword & "'" & _
                " WHERE CON_KEY=1"
    
    DBEngine.BeginTrans
    gvarDatabase.Execute lvarQuery, dbFailOnError
    DBEngine.CommitTrans
End Sub

Private Sub Class_Initialize()
    mvarConfigured = False
End Sub


